def kirill(y):
    flag=0
    for b in range(2,y):
       if y%b==0:
        flag=1
        break
    if flag==0:
        return y
    else:
        return 0
x=int(input(""))
if x<10000 and x>999:
    y=str(x)
    y1=int(y[0] + y[1])
    y2=int(y[2] + y[3])
    y3=int(y[1] + y[2])
    y4=int(y[0]+y[1]+y[2])
    y5=int(y[1]+y[2]+y[3])
    y6=int(y[0])
    y7=int(y[1])
    y8=int(y[2])
    y9=int(y[3])
    y10=int(y[0]+y[1]+y[2]+y[3])
    d=[]
    d.append(kirill(y1))
    d.append(kirill(y2))
    d.append(kirill(y3))
    d.append(kirill(y4))
    d.append(kirill(y5))
    d.append(kirill(y6))
    d.append(kirill(y7))
    d.append(kirill(y8))
    d.append(kirill(y9))
    d.append(kirill(y10))
    print(max(d))
else:
    print("0")
   

            
